package com.elitel.frame.base.controller.accessControl;

import com.elitel.frame.base.service.AcStationInfoService;
import com.elitel.frame.main.entity.acstationinfo.AcStationInfo;
import com.elitel.frame.main.entity.vo.JsonResult;
import com.elitel.frame.main.entity.vo.PageResponseVo;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 访问控制-测站信息表(AcStationInfo)表控制层
 *
 * @author makejava
 * @since 2023-11-09 15:02:33
 */
@RestController
@RequestMapping("accesscontrol/acStationInfo")
public class AcStationInfoController {
    /**
     * 服务对象
     */
    @Resource
    private AcStationInfoService acStationInfoService;

    /**
     * 获取数据分页
     *
     * @param pageInfo
     * @param stationInfo
     * @return JsonResult
     */
    @RequestMapping("/getDataPage")
    @ResponseBody
    public Object getDataPage(PageInfo pageInfo, AcStationInfo stationInfo) {
        JsonResult jr = new JsonResult();
        PageResponseVo pageResponseVo = new PageResponseVo();
        PageInfo dataPage = acStationInfoService.getDataPage(pageInfo, stationInfo);
        pageResponseVo.setRows(dataPage.getList());
        pageResponseVo.setTotal((int) dataPage.getTotal());
        jr.setData(pageResponseVo);
        jr.setSuccess(true);
        return jr;
    }


    @RequestMapping("/getDataPageByCatalogId")
    @ResponseBody
    public Object getDataPageByCatalogId(PageInfo pageInfo, AcStationInfo stationInfo) {
        JsonResult jr = new JsonResult();
        PageResponseVo pageResponseVo = new PageResponseVo();
        PageInfo dataPage = acStationInfoService.getDataPageByCatalogId(pageInfo, stationInfo);
        pageResponseVo.setRows(dataPage.getList());
        pageResponseVo.setTotal((int) dataPage.getTotal());
        jr.setData(pageResponseVo);
        jr.setSuccess(true);
        return jr;
    }


    /**
     * 获取数据分页
     *
     * @return JsonResult
     */
    @RequestMapping("/save")
    @ResponseBody
    public Object save(@RequestBody AcStationInfo stationInfo) {
        JsonResult jr = new JsonResult();
        try {
            acStationInfoService.save(stationInfo);
            jr.setSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jr.setSuccess(false);
            jr.setMsg(e.getMessage());
        }

        return jr;
    }


    /**
     * 获取数据分页
     *
     * @return JsonResult
     */
    @RequestMapping("/selectById")
    @ResponseBody
    public Object selectById(@RequestBody AcStationInfo stationInfo) {
        JsonResult jr = new JsonResult();
        AcStationInfo acStationInfo = acStationInfoService.selectById(stationInfo);
        jr.setData(acStationInfo);
        jr.setSuccess(true);
        return jr;
    }


    /**
     * 删除
     *
     * @param ids
     * @return JsonResult
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String ids) {
        JsonResult jr = null;
        try {
            jr = new JsonResult();
            acStationInfoService.deleteByIds(ids);
            jr.setSuccess(true);
            jr.setMsg("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            jr.setSuccess(false);
            jr.setMsg(e.getMessage());
        }
        return jr;
    }

}

